﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.Scalesetting
{
    public class LiveUpdateSelectHander : IRequestHandler<LiveUpdateSelectCommand, Resqults<LiveAnimalweighing>>
    {
        private readonly IBateRepository<LiveAnimalweighing> live;

        public LiveUpdateSelectHander(IBateRepository<LiveAnimalweighing> live)
        {
            this.live = live;
        }

        public async Task<Resqults<LiveAnimalweighing>> Handle(LiveUpdateSelectCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults<LiveAnimalweighing> res=new Resqults<LiveAnimalweighing> ();
                var info=await live.GetAll().FirstOrDefaultAsync(x=>x.LiveAnimalweighingNo==request.LiveAnimalweighingNo);
                if (info != null)
                {
                    res.objects = info;
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
